package com.quectel.sdk.hik8700;

import com.quectel.sdk.ex.hikisc.HikFactoryErrorException;

/**
 * 海康实例建造器
 *
 * @author: rananxin
 * @email: ryan.ran@quectel.com
 * @date: 2022-10-19 11:01:00
 */
public class Hik8700ClientBuilder {


    /**
     * 海康isc地址
     */
    private String host;
    /**
     * appKey访问凭证
     */
    private String key;
    /**
     * secretKey访问凭证
     */
    private String secret;

    private Hik8700ClientBuilder() {
    }

    public static Hik8700ClientBuilder builder() {
        return new Hik8700ClientBuilder();
    }

    public Hik8700ClientBuilder host(String host) {
        this.host = host;
        return this;
    }

    public Hik8700ClientBuilder key(String key) {
        this.key = key;
        return this;
    }

    public Hik8700ClientBuilder secret(String secret) {
        this.secret = secret;
        return this;
    }

    public <T extends AbstractHik8700BaseClient> T build(Class<T> executorCls) {
        if (host == null || key == null || secret == null) {
            throw new HikFactoryErrorException("Missing request parameter.");
        }
        try {
            T t = executorCls.newInstance();
            t.setRequester(Hik8700Requester.getInstance(key, secret, host));
            return t;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
